package com.hpq.common.domain.vo.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel(description = "分页查询响应对象")
@AllArgsConstructor
@NoArgsConstructor
public class CursorPageBaseResp<T> {
    @ApiModelProperty(value = "下一页的游标")
    private String nextCursor;
    @ApiModelProperty(value = "是否是最后一页")
    private Boolean isLast = Boolean.FALSE;
    @ApiModelProperty(value = "数据列表")
    private List<T>  data;
    public static <T> CursorPageBaseResp<T> init(CursorPageBaseResp cursorPage, List<T> data) {
        CursorPageBaseResp<T> cursorPageBaseResp = new CursorPageBaseResp<>();
        cursorPageBaseResp.setNextCursor(cursorPage.getNextCursor());
        cursorPageBaseResp.setIsLast(cursorPage.getIsLast());
        cursorPageBaseResp.setData(data);
        return cursorPageBaseResp;
    }
    @JsonIgnore
    public Boolean isEmpty(){
        return CollectionUtils.isEmpty(data);
    }
    /**
     * 初始化空游标页
     */
    public static <T> CursorPageBaseResp<T> empty(){
        return new CursorPageBaseResp<>(null,true, new ArrayList<T>());
    }

}
